package com.team16.budgetme;

import java.math.BigDecimal;
import java.text.NumberFormat;

import com.actionbarsherlock.app.SherlockFragment;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/**
 * A fragment that displays account data and buttons for adding transactions.
 *
 */
public class AccountContent extends SherlockFragment {
    AccountContentListener listener;
    private Account account;

    public interface AccountContentListener {
        public Account getAccount();
    }

    public AccountContent() {
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
            listener = (AccountContentListener) activity;
            account = listener.getAccount();
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString()
                    + " must implement AccountContentListener");
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View layout = inflater.inflate(R.layout.account_view, container, false);
        TextView balance = (TextView) layout.findViewById(R.id.current_balance);
        TextView name = (TextView) layout.findViewById(R.id.account_name);
        String accountBalance = NumberFormat.getCurrencyInstance().format(account.getBalance());

        balance.setText(accountBalance);
        name.setText(account.getName());

        if (account.getBalance().compareTo(new BigDecimal(0.0)) < 0) {
            balance.setTextColor(Color.RED);
        }

        return layout;
    }
}
